var url="http://localhost:8080/";
var loginUrl="user/login";
var userArrayUrl="user";
var userInfoUrl="user/id";
var userChangeUrl="user/id";
var teacherAddUrl="user/teacher";
var studentAddUrl="user/student";
var deleteUserUrl="user/";
var schoolPage="schoolPage";
var scoreUrl="score";
var scoreByParamUrl="score/param";



var scoreRankByTId="score/teacher";
var scoreMyToTeacher="score/myToTeacher";

var scoreRoleIdUrl="score/roleRank";

var userNumberOneUrl="score/userNumberOne";



var departmentArray="department";
var departmentChangeUrl="department/id";
var insertChangeUrl="department";
var deleteChangeUrl="department/";

var schoolLoginUserInfo="schoolLoginUserInfo";

var userInfoId="userInfoId";

var findRole="findRole";
var nameLike="nameLike";
var findDepartment="findDepartment";

function error(data){
    if(data!=null){
        var res = eval('(' + JSON.stringify(data) + ')');
        alert(res.resultMessage);
    }
    return;
}
function toLogin(){
    localStorage.clear();
    top.location.href="../login.html";
}

function timestampToTime(timestamp) {
    // var date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    var date = new Date( timestamp);
    Y = date.getFullYear() + '-';
    M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
    D = date.getDate() + ' ';
    h = date.getHours() + ':';
    m = date.getMinutes() + ':';
    s = date.getSeconds();
    return Y+M+D;
}

function workYear(date){
    Date.prototype.diff = function(date){
        return (this.getTime() - date)/(24 * 60 * 60 * 1000);
    }
// 构造两个日期，分别是系统时间和2013/04/08 12:43:45
    var now = new Date();
    var date = new Date(date);
// 调用日期差方法，求得参数日期与系统时间相差的天数
    var diff = now.diff(date);
// 打印日期差
    var workDate;
    if(diff/365<1){
        if(diff/30<1){
            workDate=parseInt(diff)+"天";
        }else{
            workDate=parseInt(diff/30)+"月";
        }
    }else{
        workDate=parseInt(diff/365)+"年";
    }
    return workDate;
}


function roleName(role){
    if(role ==1){
        return "学生";
    }
    if(role ==2){
        return "教师";
    }
    if(role ==3){
        return "专家";
    }
    if(role ==4){
        return "管理员";
    }
}

function sexName(sex){
    if(sex ==1){
        return "男";
    }
    if(sex ==2){
        return "女";
    }
}

function sorecText(data){
    if(data == null || data =="null"){
        return "暂无评分数据";
    }else{
        return data;
    }
}

function getDepArray() {
    $.ajax({
        "url": url + departmentArray,
        "type": 'get',
        "dataType": "json",
        "success": function (data) {
            var res = eval('(' + JSON.stringify(data) + ')');
            if (res.resultCode != 200) {
                error(data);
                return;
            }
            depAppand(res.obj);

        },
        "error": error()
    })
}

